<template>
  <ant-modal
    modalWidth="1200"
    modalHeight="750"
    :visible="open"
    modal-title="月报详情"
    :adjust-size="false"
    @cancel="cancel"
  >
    <a-form-model ref="form" slot="content" layout="vertical">
      <a-row :gutter="32">
        <a-col :span="12">
          <a-row :gutter="32">
            <a-col :span="7" style="margin-left: 20px"
              >单位名称：{{ deptName }}
            </a-col>
            <a-col :span="7" style="text-align: center"
              >年份：{{ times }}
            </a-col>
            <a-col :span="7" style="text-align: right"
              >已完成： {{ istijiao }}/12</a-col
            >
          </a-row>
        </a-col>
        <a-col :span="10" style="margin-left: 20px">
          {{ deptName }}纪检监察工作情况月报表 {{ months }}
        </a-col>
        <a-col :span="12">
          <advance-table
            title=" "
            :pagination="{
              current: queryParam.pageNum,
              pageSize: queryParam.pageSize,
              total: total,
              showSizeChanger: true,
              showLessItems: true,
              showQuickJumper: true,
              showTotal: (total, range) =>
                `第 ${range[0]}-${range[1]} 条，总计 ${total} 条`,
              onChange: changeSize,
              onShowSizeChange: onShowSizeChange,
            }"
            tableKey="base-bizMonthDept-index-table"
            rowKey="id"
            size="middle"
            @refresh="getList"
            :columns="columns"
            :data-source="bizMonthDeptList"
            :loading="loading"
            :format-conditions="true"
          >
            <span slot="operation" slot-scope="{ text, record }">
              <a
                @click="handleUpdate(record)"
                v-hasPermi="['biz:bizMonthDept:tianbao']"
                v-if="record.status == '0'"
              >
                填报
              </a>

              <a
                @click="handleUpdateCheHui(record)"
                v-hasPermi="['biz:bizMonthDept:tianbao']"
                v-if="record.status == '1'"
              >
                撤回
              </a>
              <a-divider
                type="vertical"
                v-hasPermi="['biz:bizMonthDept:details']"
                v-if="record.status == '1'"
              />

              <a
                @click="handleDetails(record)"
                v-hasPermi="['biz:bizMonthDept:details']"
                v-if="record.status == '1'"
              >
                详情
              </a>
            </span>
            <span slot="rowindex" slot-scope="{ index }">
              {{ index + 1 }}
            </span>
            <span slot="status" slot-scope="{ text }">
              <a-tag v-if="text == '0'">未填报</a-tag>
              <a-tag v-else color="#87d068">已填报</a-tag>
            </span>
            <span slot="name" slot-scope="{ text, record }">
              {{ text }}--{{
                record.times.substring(5, 7).replace("0", "")
              }}月份
            </span>
          </advance-table>
        </a-col>
        <a-col :span="12">
          <BizMonthDeptDetailsIndex
            ref="BizMonthDeptDetailsIndex"
            v-if="open"
            @ok="getList"
          />
        </a-col>
      </a-row>
    </a-form-model>
    <template slot="footer">
      <!-- <a-button @click="cancel"> 取 消 </a-button> -->
      <a-button type="primary" @click="cancel"> 关 闭 </a-button>
    </template>
  </ant-modal>
</template>
<script>
import {
  listBizMonthDept,
  delBizMonthDept,
  exportBizMonthDept,
  updateBizMonthDept,
} from "@/api/biz/bizMonthDept";
import { listBizMonthModel } from "@/api/biz/bizMonthModel";
import AdvanceTable from "@/components/pt/table/AdvanceTable";
// import BizMonthDeptAddForm from "@/views/biz/monthdept/modules/BizMonthDeptAddForm";
import BizMonthDeptDetailsIndex from "@/views/biz/monthdeptdetials/index";
import AntModal from "@/components/pt/dialog/AntModal";
export default {
  name: "BizMonthDept",
  components: {
    AdvanceTable,
    AntModal,
    BizMonthDeptDetailsIndex,
  },
  data() {
    return {
      showAddModal: false,
      showEditModal: false,
      deptName: "",
      times: "",
      months: "",
      tijiao: 12,
      istijiao: 0,
      // 遮罩层
      loading: true,
      open: false,
      formTitle: "月报管理",
      // 选中数组
      ids: [],
      // 选中的主键集合
      selectedRowKeys: [],
      // 选中的数据集合
      selectedRows: [],
      // 高级搜索 展开/关闭
      advanced: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // label的百分比
      labelCol: { span: 6 },
      // 内容区域的百分比
      wrapperCol: { span: 18 },
      // 月报管理表格数据
      bizMonthDeptList: [],
      // 类型字典
      typeOptions: [],
      modelListOptions: [],
      // 查询参数
      queryParam: {
        pageNum: 1,
        pageSize: 12,
        userId: undefined,

        deptId: undefined,

        userName: undefined,

        deptName: undefined,

        type: undefined,
      },
      columns: [
        {
          title: "序号",
          dataIndex: "rowindex",
          ellipsis: true,
          align: "center",
          width: "65px",
          scopedSlots: { customRender: "rowindex" },
        },
        {
          title: "月报任务名称",
          dataIndex: "name",
          ellipsis: true,
          align: "left",
          width: "55%",
          scopedSlots: { customRender: "name" },
        },

        {
          title: "填报状态",
          dataIndex: "status",
          ellipsis: true,
          align: "center",
          width: "15%",
          scopedSlots: { customRender: "status" },
        },

        {
          title: "操作",
          dataIndex: "operation",
          align: "left",
          width: "20%",
          scopedSlots: { customRender: "operation" },
        },
      ],
    };
  },
  created() {
    this.getDicts("baogao_type").then((response) => {
      this.typeOptions = response.data;
    });
  },
  methods: {
    cancel() {
      this.open = false;
      this.$emit("close");
    },
    getModelList() {
      listBizMonthModel(this.queryParam).then((response) => {
        this.modelListOptions = response.data.list;
      });
    },
    handleMonthDept(row) {
      this.open = true;
      this.spinning = !this.spinning;
      const bizMonthDeptId = row.id;
      this.queryParam.modelId = bizMonthDeptId;
      this.getList();
      this.deptName = row.deptName;
      this.times = row.times.substring(0, 4) + "年";
    },
    /** 查询月报管理列表 */
    getList() {
      this.loading = true;
      listBizMonthDept(this.queryParam).then((response) => {
        this.bizMonthDeptList = response.data.list;
        var counts = 0;
        for (var i = 0; i < this.bizMonthDeptList.length; i++) {
          if (this.bizMonthDeptList[i].status === "1") {
            counts = counts + 1;
          }
        }
        this.istijiao = counts;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 类型字典翻译
    typeFormat(row) {
      if (row.type) {
        return this.selectDictLabel(this.typeOptions, row.type);
      } else {
        return "";
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParam.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParam = {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,

        deptId: undefined,

        userName: undefined,

        deptName: undefined,

        type: undefined,
      };
      this.handleQuery();
    },
    /** 翻页操作 */
    onShowSizeChange(current, pageSize) {
      this.queryParam.pageSize = pageSize;
      this.getList();
    },
    /** 翻页操作 */
    onSizeChange(current, size) {
      this.queryParam.pageNum = 1;
      this.queryParam.pageSize = size;
      this.getList();
    },
    /** 翻页操作 */
    changeSize(current, pageSize) {
      this.queryParam.pageNum = current;
      this.queryParam.pageSize = pageSize;
      this.getList();
    },
    /** 翻页操作 */
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRows = selectedRows;
      this.ids = this.selectedRows.map((item) => item.id);
      this.single = selectedRowKeys.length !== 1;
      this.multiple = !selectedRowKeys.length;
    },
    /** 查询折叠和展开操作 */
    toggleAdvanced() {
      this.advanced = !this.advanced;
    },
    handleAdd() {
      this.showAddModal = true;
      this.$nextTick(() => this.$refs.bizMonthDeptAddForm.handleAdd());
    },
    handleUpdate(record) {
      this.open = true;
      this.$nextTick(() =>
        this.$refs.BizMonthDeptDetailsIndex.getListById(record.id, true)
      );
      this.months =
        "-" + record.times.substring(5, 7).replace("0", "") + "月份";
    },
    handleUpdateCheHui(record) {
      var that = this;

      this.$confirm({
        title: "确认撤回填报数据?",
        onOk() {
          record.status = "0";
          return updateBizMonthDept(record).then(() => {
            that.getList();
            that.$message.success("撤回成功", 3);
          });
        },
        onCancel() {},
      });
    },
    handleDetails(record) {
      this.open = true;
      this.$nextTick(() =>
        this.$refs.BizMonthDeptDetailsIndex.getListById(record.id, false)
      );
      this.months =
        "-" + record.times.substring(5, 7).replace("0", "") + "月份";
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      var that = this;
      const bizMonthDeptIds = row.id || this.ids;
      this.$confirm({
        title: "确认删除所选中数据?",
        onOk() {
          return delBizMonthDept(bizMonthDeptIds).then(() => {
            that.onSelectChange([], []);
            that.getList();
            that.$message.success("删除成功", 3);
          });
        },
        onCancel() {},
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      var that = this;
      this.$confirm({
        title: "是否确认导出?",
        content: "此操作将导出当前条件下所有数据而非选中数据",
        onOk() {
          return exportBizMonthDept(that.queryParam).then((response) => {
            that.download(response.msg);
            that.$message.success("导出成功", 3);
          });
        },
        onCancel() {},
      });
    },
  },
};
</script>
